<template>
  <div class="app-container">
    <el-row v-if="!convertBuiness">
      <el-col :span="24">
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        >
          <el-form-item label="活动名称" prop="activityName">
            <el-input
              v-model="queryParams.activityName"
              placeholder="请输入活动名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="主办单位" prop="sponsor">
            <el-input
              v-model="queryParams.sponsor"
              placeholder="请输入主办单位名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="发起时间" prop="initiationTime">
            <el-date-picker
              clearable
              v-model="queryParams.initStartTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择开始时间"
            >
            </el-date-picker>
            至
            <el-date-picker
              clearable
              v-model="queryParams.initEndTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择结束时间"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>
        <el-table
          :row-style="{ height: '30px' }"
          :cell-style="{ padding: '0px' }"
          height="300"
          border
          v-loading="loading"
          :data="trainingList"
          highlight-current-row
        >
          <el-table-column label="序号" type="index" :index="indexMethod" />
          <el-table-column
            label="状态"
            align="center"
            prop="status"
            v-if="columns[0].visible"
          />
          <el-table-column
            label="活动名称"
            align="center"
            prop="activityName"
            v-if="columns[1].visible"
            width="200"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="主办单位"
            align="center"
            prop="sponsor"
            v-if="columns[3].visible"
            :show-overflow-tooltip="true"
            width="100"
          />
          <el-table-column
            label="协办单位"
            align="center"
            prop="organizer"
            v-if="columns[3].visible"
            :show-overflow-tooltip="true"
            width="100"
          />
          <el-table-column
            label="承办单位"
            align="center"
            prop="undertaker"
            v-if="columns[3].visible"
            :show-overflow-tooltip="true"
            width="100"
          />
          <el-table-column
            label="类别"
            align="center"
            prop="type"
            v-if="columns[4].visible"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="发起时间"
            align="center"
            prop="initiationTime"
            width="120"
            v-if="columns[5].visible"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span>{{
                parseTime(scope.row.initiationTime, "{y}-{m}-{d} ")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="形式"
            align="center"
            prop="lays"
            v-if="columns[5].visible"
          />
          <el-table-column
            label="开始时间"
            align="center"
            prop="startTime"
            width="130"
            v-if="columns[6].visible"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span>{{
                parseUTCTime(scope.row.startTime, "{y}-{m}-{d} {hh}:{mm}")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="结束时间"
            align="center"
            prop="endTime"
            width="130"
            v-if="columns[7].visible"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span>{{
                parseUTCTime(scope.row.endTime, "{y}-{m}-{d} {hh}:{mm}")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="地点"
            align="center"
            prop="location"
            v-if="columns[8].visible"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="创建人"
            align="center"
            prop="creationName"
            v-if="columns[10].visible"
            :show-overflow-tooltip="true"
            width="100"
          />
          <el-table-column
            label="创建时间"
            align="center"
            prop="creationTime"
            width="120"
            v-if="columns[11].visible"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span>{{
                parseTime(scope.row.creationTime, "{y}-{m}-{d}")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="联系人"
            align="center"
            prop="contacts"
            v-if="columns[12].visible"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="联系电话"
            align="center"
            prop="telephone"
            v-if="columns[13].visible"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="报名截止"
            align="center"
            prop="deadlineTime"
            width="120"
            v-if="columns[14].visible"
            :show-overflow-tooltip="true"
          >
            <template slot-scope="scope">
              <span>{{
                parseTime(scope.row.deadlineTime, "{y}-{m}-{d}")
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="参训人数"
            align="center"
            prop="partPersonNum"
            v-if="columns[16].visible"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="参训企业数"
            width="100"
            align="center"
            prop="partEnterNum"
            v-if="columns[17].visible"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="报名企业数量"
            width="100"
            align="center"
            prop="regiEnterprise"
            v-if="columns[18].visible"
            :show-overflow-tooltip="true"
          >
          </el-table-column>
          <el-table-column
            label="满意度平均分"
            width="100"
            align="center"
            prop="satisfactionScore"
            v-if="columns[19].visible"
          />
          <el-table-column
            label="费用"
            align="center"
            prop="fee"
            v-if="columns[20].visible"
          />
          <el-table-column label="附件" align="center" prop="fileUpload">
            <template slot-scope="scope">
              <el-button
                @click="handlePictureCardPreview(scope.row.fileUpload)"
                size="small"
                v-if="scope.row.fileUrl != null && scope.row.fileUrl != ''"
                type="text"
                >附件</el-button
              >
              <el-button size="small" v-else type="text">无附件</el-button>
            </template>
          </el-table-column>
          <el-table-column label="总结报告" align="center" prop="partUpload">
            <template slot-scope="scope">
              <el-button
                @click="handlePictureCardPreview(scope.row.partUpload)"
                size="small"
                type="text"
                >总结报告</el-button
              >
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
            width="85px"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="handleSelect(scope.row, scope.$index)"
                title="查看"
              ></el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
    <!-- 添加或修改活动信息培训对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="800px"
      append-to-body
      @close="closeTrain"
    >
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="80px"
        :inline="true"
      >
        <div v-if="addSign !== 0">
          <el-descriptions title="">
            <el-descriptions-item label="序号">
              <el-tag size="medium">{{ form.index }}</el-tag>
            </el-descriptions-item>
          </el-descriptions>
        </div>
        <el-form-item label="活动名称" prop="activityName" label-width="110px">
          <el-input
            v-model="form.activityName"
            placeholder="请输入活动名称"
            :disabled="ReadOnly"
            style="width: 202.5px"
          />
        </el-form-item>
        <el-form-item
          label="发起时间"
          prop="initiationTime"
          label-width="110px"
        >
          <el-date-picker
            clearable
            v-model="form.initiationTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择发起时间"
            style="width: 202.5px"
            :disabled="ReadOnly"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="主办单位" prop="sponsor" label-width="110px">
          <el-input
            v-model="form.sponsor"
            type="textarea"
            placeholder="请选择主办单位"
            readonly
            :disabled="ReadOnly"
            style="width: 525px"
            @focus="enterprise(1)"
          />
        </el-form-item>
        <el-form-item label="协办单位" prop="organizer" label-width="110px">
          <el-input
            v-model="form.organizer"
            type="textarea"
            placeholder="请选择协办单位"
            readonly
            :disabled="ReadOnly"
            style="width: 525px"
            @focus="enterprise(2)"
          />
        </el-form-item>
        <el-form-item label="承办单位" prop="undertaker" label-width="110px">
          <el-input
            v-model="form.undertaker"
            type="textarea"
            placeholder="请选择承办单位"
            readonly
            :disabled="ReadOnly"
            style="width: 525px"
            @focus="enterprise(3)"
          />
        </el-form-item>
        <el-form-item label="类别" prop="type" label-width="110px">
          <!--          <el-input v-model="form.type" placeholder="请输入类别" :disabled="ReadOnly" style="width: 202.5px" />-->
          <el-select
            v-model="form.type"
            placeholder="请选择形式"
            style="width: 202.5px"
            :disabled="ReadOnly"
          >
            <el-option label="公益" value="公益"></el-option>
            <el-option label="收费" value="收费"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="形式" prop="lays" label-width="110px">
          <el-select
            v-model="form.lays"
            placeholder="请选择形式"
            style="width: 202.5px"
            :disabled="ReadOnly"
          >
            <el-option label="线下" value="线下"></el-option>
            <el-option label="线上" value="线上"></el-option>
            <el-option label="线上+线下" value="线上+线下"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime" label-width="110px">
          <el-date-picker
            v-model="form.startTime"
            type="datetime"
            placeholder="选择日期时间"
            value-format="yyyy-MM-dd HH:mm"
            :disabled="ReadOnly"
            style="width: 202.5px"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime" label-width="110px">
          <el-date-picker
            v-model="form.endTime"
            type="datetime"
            placeholder="选择日期时间"
            value-format="yyyy-MM-dd HH:mm"
            :disabled="ReadOnly"
            style="width: 202.5px"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="地点" prop="location" label-width="110px">
          <el-input
            v-model="form.location"
            placeholder="请输入地点"
            :disabled="ReadOnly"
            style="width: 202.5px"
          />
        </el-form-item>
        <el-form-item label="联系人" prop="contacts" label-width="110px">
          <el-input
            v-model="form.contacts"
            placeholder="请输入联系人"
            :disabled="ReadOnly"
            style="width: 202.5px"
          />
        </el-form-item>
        <el-form-item label="联系电话" prop="telephone" label-width="110px">
          <el-input
            v-model="form.telephone"
            placeholder="请输入联系电话"
            :disabled="ReadOnly"
            style="width: 202.5px"
          />
        </el-form-item>
        <el-form-item label="报名截止" prop="deadlineTime" label-width="110px">
          <el-date-picker
            clearable
            v-model="form.deadlineTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择报名截止"
            style="width: 202.5px"
            :disabled="ReadOnly"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="审核人"
          prop="examineName"
          label-width="110px"
          v-if="form.sendType === 'groupSend'"
        >
          <el-input
            v-model="form.examineName"
            placeholder="请输入审核人"
            @focus="selectOpen(0)"
            :disabled="ReadOnly"
            style="width: 202.5px"
          />
        </el-form-item>
        <el-form-item label="费用" prop="fee" label-width="110px">
          <el-input
            v-model="form.fee"
            placeholder="请输入费用"
            :disabled="ReadOnly"
            style="width: 202.5px"
          />
        </el-form-item>
        <el-form-item label="区域" prop="region" label-width="110px">
          <Treeselect
            v-model="form.region"
            :options="optionsArea"
            style="width: 202.5px"
            :flat="true"
            :show-count="true"
            :normalizer="normalizer"
            placeholder="请选择区域"
            :disabled="ReadOnly"
          />
        </el-form-item>
        <el-form-item label="创建人" prop="creationName" label-width="110px">
          <el-input
            v-model="form.creationName"
            placeholder="请输入创建人"
            disabled="true"
            style="width: 202.5px"
          />
        </el-form-item>
        <el-form-item label="创建时间" prop="creationTime" label-width="110px">
          <el-date-picker
            clearable
            v-model="form.creationTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间"
            style="width: 202.5px"
            disabled="true"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发送方式" prop="sendType" label-width="110px">
          <el-radio-group v-model="form.sendType" :disabled="ReadOnly">
            <el-radio label="oneClick">一键发送</el-radio>
            <el-radio label="groupSend">分类群发</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          v-if="form.sendType === 'groupSend'"
          label="群发内容"
          prop="receiverName"
          label-width="110px"
        >
          <el-input
            v-model="form.receiverName"
            type="textarea"
            placeholder="请输入内容"
            style="width: 500px"
            @focus="handleTextAreaFocus"
            :disabled="ReadOnly"
          />
        </el-form-item>
        <el-form-item label="附件" prop="uploadFile" label-width="110px">
          <file-view
            v-if="show"
            :limit="1"
            :type="typeSelect"
            :businessId="form.fileUpload"
            :businessCode="businessCode"
            style="width: 500px"
          ></file-view>
        </el-form-item>
        <el-form-item
          label="审核状态"
          prop="examineStatus"
          label-width="110px"
          v-if="
            (addSign === 3 || addSign === 2) && form.sendType === 'oneClick'
          "
        >
          <el-radio-group v-model="form.examineStatus" :disabled="ReadOnly">
            <el-radio label="through">审核通过</el-radio>
            <el-radio label="termination">审核不通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="终止原因"
          prop="endReason"
          v-if="
            form.examineStatus === 'termination' &&
            (addSign === 3 || addSign === 2)
          "
          label-width="110px"
        >
          <el-input
            v-model="form.endReason"
            type="textarea"
            placeholder="请输入终止原因"
            style="width: 440px"
            maxlength="300"
            show-word-limit
            :disabled="ReadOnly"
          />
        </el-form-item>
        <el-form-item
          label="参训人数"
          prop="partPersonNum"
          v-if="addSign === 3 && form.examineStatus == 'through'"
          label-width="110px"
        >
          <el-input
            v-model="form.partPersonNum"
            placeholder="请输入参训人数"
            type="number"
            :min="0"
            style="width: 202.5px"
          />
        </el-form-item>
        <el-form-item
          label="参训企业数量"
          prop="partEnterNum"
          v-if="addSign === 3 && form.examineStatus == 'through'"
          label-width="110px"
        >
          <el-input
            v-model="form.partEnterNum"
            placeholder="请输入参训企业数量"
            type="number"
            :min="0"
            style="width: 202.5px"
          />
        </el-form-item>
        <el-form-item
          label="满意度平均分"
          prop="satisfactionScore"
          v-if="addSign === 3 && form.examineStatus == 'through'"
          label-width="110px"
        >
          <el-input
            v-model="form.satisfactionScore"
            placeholder="请输入满意度平均分"
            type="number"
            :min="0"
            style="width: 202.5px"
          />
        </el-form-item>
        <el-form-item
          label="总结报告"
          prop="partUpload"
          v-if="addSign === 3 && form.examineStatus == 'through'"
          label-width="110px"
        >
          <file-view
            :limit="1"
            v-if="show"
            :type="uploadType"
            :businessId="form.partUpload"
            :businessCode="businessCode"
            style="width: 500px"
          ></file-view>
        </el-form-item>
      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
        style="display: flex; justify-content: center"
        v-if="addSign !== 2"
      >
        <el-button type="primary" @click="submitForm" v-if="addSign !== 3"
          >确 定</el-button
        >
        <el-button
          type="primary"
          @click="score"
          v-if="addSign === 3 && form.examineStatus == 'through'"
          >评 分</el-button
        >
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
    <!--    附件展示对话框-->
    <el-dialog
      title="查看附件"
      :visible.sync="openFileList"
      width="500px"
      append-to-body
      v-if="openFileList"
    >
      <UploadFile
        :upload-id="uploadId"
        :business-code="businessCode"
      ></UploadFile>
    </el-dialog>
  </div>
</template>

<script>
import {
  listTrainingOrgId,
  getTraining,
  updateScore,
  addTraining,
  updateTraining,
} from "@/api/activity/training";
import { listType } from "@/api/maintype/type";
import FileView from "@/components/FileView/index";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import UploadFile from "../upload/index.vue";

import { listArea } from "@/api/area/area";
export default {
  name: "Training",
  components: {
    UploadFile,
    Treeselect,
    FileView,
  },
  props: {
    bId: {
      type: String,
      default: "",
    },
    receiverId: {
      type: Number,
      default: 0,
    },
    enterpriseName: {
      type: String,
      default: "",
    },
    initiationId: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      uuid: "",
      edit: "add",
      menuId: "2079",
      isClick: true,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      typeCode: "train",
      // 活动信息培训表格数据
      trainingList: [],
      uploadId: null,
      openFileList: false,
      // 弹出层标题
      title: "",
      //详情状态
      ReadOnly: false,
      //行政区域
      optionsArea: null,
      // 是否显示弹出层
      open: false,
      //判断对话框是否新增或编辑
      addSign: 0,
      //图片的标志位
      show: false,
      dialogImageUrl: null,
      ImgDig: false,
      uploadType: 1,
      typeSelect: 0,
      businessCode: "train",
      //主分类
      options: null,
      userType: "1",
      sign: "2",
      pickerOptions: {
        disabledDate: time => {
          // 禁用今天之前的日期选择
          return time.getTime() < new Date().getTime() - 24 * 60 * 60 * 1000;
        },
      },

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 15,
        activityName: null,
        sponsorId: null,
        supplierId: null,
        sponsor: null,
        undertakerId: null,
        undertaker: null,
        organizerId: null,
        organizer: null,
        belongTo: null,
        initStartTime: null,
        initEndTime: null,
      },
      activityId: null,
      convertBuiness: false,
      openUser: false,
      // 列信息
      columns: [
        { key: 0, label: `状态`, prop: "status", visible: true },
        { key: 1, label: `活动名称`, prop: "activityName", visible: true },
        { key: 2, label: `发起单位`, prop: "initiationUnit", visible: true },
        { key: 3, label: `主办单位`, prop: "sponsor", visible: true },
        { key: 4, label: `类别`, prop: "type", visible: true },
        { key: 5, label: `形式`, prop: "lays", visible: true },
        { key: 6, label: `发起时间`, prop: "initiationTime", visible: true },
        { key: 7, label: `开始时间`, prop: "startTime", visible: true },
        { key: 8, label: `结束时间`, prop: "endTime", visible: true },
        { key: 9, label: `地点`, prop: "location", visible: true },
        { key: 10, label: `创建人`, prop: "creationName", visible: true },
        { key: 11, label: `创建时间`, prop: "creationTime", visible: true },
        { key: 12, label: `联系人`, prop: "contacts", visible: true },
        { key: 13, label: `联系电话`, prop: "telephone", visible: true },
        { key: 14, label: `报名截止`, prop: "deadlineTime", visible: true },
        { key: 15, label: `审核人`, prop: "examineName", visible: true },
        { key: 16, label: `参训人数`, prop: "partPersonNum", visible: true },
        { key: 17, label: `参训企业数量`, prop: "partEnterNum", visible: true },
        { key: 18, label: "报名企业数", prop: "regiEnterprise", visible: true },
        {
          key: 19,
          label: `满意度平均分`,
          prop: "satisfactionScore",
          visible: true,
        },
        { key: 20, label: `费用`, prop: "fee", visible: true },
      ],
      Regi: false,
      // 表单参数
      form: {},
      activityName: [
        { required: true, message: "请输入活动名称", trigger: "blur" },
      ],
      rules: {
        deadlineTime: [
          { required: true, message: "请选择报名截止时间", trigger: "blur" },
          {
            validator: (rule, value, callback) => {
              const startTime = this.form.startTime;
              const endTime = this.form.endTime;
              if (value && (value > startTime || value > endTime)) {
                callback(new Error("报名截止时间不能大于开始时间和结束时间"));
              } else {
                callback();
              }
            },
            trigger: "blur",
          },
        ],
        startTime: [
          { required: true, message: "请选择开始时间", trigger: "blur" },
          {
            validator: (rule, value, callback) => {
              const deadlineTime = this.form.deadlineTime;
              const endTime = this.form.endTime;
              if (value && value > endTime) {
                callback(new Error("开始时间不能大于结束时间"));
              } else if (value && value < deadlineTime) {
                callback(new Error("开始时间不能小于报名截止时间"));
              } else {
                callback();
              }
            },
            trigger: "blur",
          },
        ],
        endTime: [
          { required: true, message: "请选择结束时间", trigger: "blur" },
          {
            validator: (rule, value, callback) => {
              const startTime = this.form.startTime;
              if (value && value < startTime) {
                callback(new Error("结束时间不能小于开始时间"));
              } else {
                callback();
              }
            },
            trigger: "blur",
          },
        ],
        creationName: [
          { required: true, message: "请输入创建人", trigger: "blur" },
        ],
        creationTime: [
          { required: true, message: "请选择创建时间", trigger: "blur" },
        ],
        initiationUnit: [
          { required: true, message: "请输入发起单位", trigger: "blur" },
        ],
        sponsor: [
          { required: true, message: "请输入主办单位", trigger: "blur" },
        ],
        initiationTime: [
          { required: true, message: "请选择发起时间", trigger: "blur" },
        ],
        type: [{ required: true, message: "请输入类别", trigger: "blur" }],
        lays: [{ required: true, message: "请选择形式", trigger: "blur" }],
        location: [{ required: true, message: "请输入地点", trigger: "blur" }],
        contacts: [
          { required: true, message: "请输入联系人", trigger: "blur" },
        ],
        telephone: [
          { required: true, message: "请输入联系电话", trigger: "blur" },
        ],
        examineName: [
          { required: true, message: "请输入审核人", trigger: "change" },
        ],
        fee: [
          { required: true, message: "请输入费用", trigger: "blur" },
          { validator: this.validateNumber, trigger: "blur" },
        ],
        sendType: [
          { required: true, message: "请选择发送方式", trigger: "blur" },
        ],
        receiverName: [
          { required: true, message: "请输入群发内容", trigger: "change" },
        ],
        partPersonNum: [
          { required: true, message: "请输入参训人数", trigger: "blur" },
          { validator: this.validateNumber, trigger: "blur" },
        ],
        partEnterNum: [
          { required: true, message: "请输入参训企业数量", trigger: "blur" },
          { validator: this.validateNumber, trigger: "blur" },
        ],
        satisfactionScore: [
          { required: true, message: "请输入满意度平均分", trigger: "blur" },
          { validator: this.validateNumber, trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.listType();
    this.area();
  },
  methods: {
    //费用校验
    validateNumber(rule, value, callback) {
      if (value === "" || /^[0-9]+(\.[0-9]+)?$/.test(value)) {
        callback();
      } else {
        callback(new Error("请输入合法的数字"));
      }
    },
    /** 查询活动信息培训列表 */
    getList() {
      this.loading = true;
      this.queryParams.supplierName = this.enterpriseName;
      listTrainingOrgId(this.queryParams).then(response => {
        this.trainingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    area() {
      listArea({}).then(response => {
        this.optionsArea = response.data;
      });
    },
    parseUTCTime(time, format) {
      const date = new Date(time.replace("T", " ").replace("+08", ""));
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, "0");
      const day = String(date.getDate()).padStart(2, "0");
      const hours = String(date.getHours()).padStart(2, "0");
      const minutes = String(date.getMinutes()).padStart(2, "0");
      return format
        .replace("{y}", year)
        .replace("{m}", month)
        .replace("{d}", day)
        .replace("{hh}", hours)
        .replace("{mm}", minutes);
    },
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.areaId,
        label: node.areaName,
        isDisabled: node.parentId == "000000" ? true : false,
        children: node.list.length > 0 ? node.list : 0,
      };
    },
    //获取树节点数据
    listType() {
      listType({ typeCode: "train" }).then(res => {
        console.log(res);
        this.options = res.data;
      });
    },
    selectUser(userId, userName) {
      this.$set(this.form, "examineId", userId);
      this.$set(this.form, "examineName", userName);
    },

    // //报名截止日期控件
    // dateOptions(time) {
    //   return time.getTime() < Date.now() - 24 * 60 * 60 * 1000
    //:picker-options="{ disabledDate: dateOptions }"
    // },
    //关闭对话框
    closeTrain() {
      this.ReadOnly = false;
      this.show = false;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.show = false;
      this.addSign = 0;
      this.reset();
    },
    //转商机
    convertBusiness(row) {
      this.uuid = this.guid();
      this.edit = "add";
      this.isClick = true;
      this.convertBuiness = true;
    },
    closeEle() {
      this.convertBuiness = false;
    },
    //点击接收方文本域,弹出选择当前用户在企业管理中的企业信息
    handleTextAreaFocus() {
      this.openUser = true;
    },
    selectOpen(type) {
      this.userType = 1;
      this.$refs.selectRole.show();
    },
    //获取当前用户在企业管理中的企业信息
    selectEnterprise(selection) {
      this.form.enterpriseId = selection.map(item => item.enterpriseId);
      this.form.receiverName = selection
        .map(item => item.enterpriseName)
        .join(",");
      console.log(this.form);
      this.close();
    },
    guid() {
      function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
      }
      return (
        S4() +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        "-" +
        S4() +
        S4() +
        S4()
      );
    },
    close() {
      this.openUser = false;
    },
    // 表单重置
    reset() {
      this.form = {
        activityId: null,
        activityName: null,
        initiationUnit: null,
        sponsor: null,
        type: null,
        initiationTime: null,
        lays: null,
        startTime: null,
        endTime: null,
        location: null,
        receiverId: null,
        receiverName: null,
        operateTime: null,
        status: null,
        operateId: null,
        operateName: null,
        departmentId: null,
        departmentName: null,
        organizationId: null,
        organizationName: null,
        createId: null,
        creationName: null,
        creationTime: null,
        belongTo: null,
        classificationId: null,
        contacts: null,
        telephone: null,
        deadlineTime: null,
        examineId: null,
        examineName: null,
        fileUpload: null,
        partPersonNum: null,
        partEnterNum: null,
        satisfactionScore: null,
        //客户id数组
        enterpriseId: [],
        sendType: null,
        partUpload: null,
        activityPicture: null,
        region: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.queryParams.initStartTime > this.queryParams.initEndTime) {
        this.$message.error("请重新添加日期查询条件");
      } else {
        this.getList();
      }
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.initStartTime = null;
      this.queryParams.initEndTime = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //树点击事件
    getNode(data, node, obj) {
      console.log(data);
      if (data.parentId != "00000000-0000-0000-0000-000000000000") {
        this.queryParams.classificationId = data.id;
      } else {
        this.queryParams.classificationId = null;
      }
      this.getList();
    },
    //当有值的时候，默认打开对话框为分类群发，没值为一键发送
    sendTrain() {
      if (this.form.receiverName !== null) {
        this.sendType = "groupSend";
      } else {
        this.sendType = "oneClick";
      }
    },
    //序号展示
    indexMethod(index) {
      return (
        (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1
      );
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.listType();
      this.sendTrain();
      this.form.fileUpload = new Date().getTime();
      this.form.creationTime = new Date();
      this.form.activityPicture = new Date().getTime() + 20;
      this.form.partUpload = new Date().getTime() + 40;
      this.form.creationName = this.$store.state.user.name;
      if (this.queryParams.classificationId === null) {
        this.form.classificationId = "650c44e1-b575-4b62-9d54-1ba9d1e8abb7";
      } else {
        this.form.classificationId = this.queryParams.classificationId;
      }
      this.addSign = 0;
      this.typeSelect = 0;
      this.title = "添加活动信息培训";
      this.open = true;
      this.show = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row, index) {
      this.reset();
      this.listType();
      const activityId = row.activityId || this.ids;
      getTraining(activityId).then(response => {
        this.form = response.data;
        if (this.form.activityPicture === null) {
          this.form.activityPicture = new Date().getTime();
        }
        this.sendTrain();
        this.open = true;
        this.typeSelect = 1;
        this.show = true;
        this.addSign = 1;
        this.form.index = index + 1;
        //把接收方的id转成数组
        this.form.enterpriseId = this.form.receiverId.split(",");
        this.title = "修改活动信息培训";
      });
    },
    /** 查看按钮操作 */
    handleSelect(row, index) {
      this.reset();
      const activityId = row.activityId || this.ids;
      getTraining(activityId).then(response => {
        this.form = response.data;
        this.ReadOnly = true;
        this.open = true;
        this.typeSelect = 2;
        this.form.index = index + 1;
        this.addSign = 2;
        this.show = true;
        this.title = "查看活动信息培训";
      });
    },
    //评分
    handleScore(row, index) {
      const activityId = row.activityId || this.ids;
      getTraining(activityId).then(response => {
        this.form = response.data;
        this.ReadOnly = true;
        this.open = true;
        this.typeSelect = 2;
        this.form.index = index + 1;
        this.addSign = 3;
        this.show = true;
        //把接收方的id转成数组
        this.form.enterpriseId = this.form.receiverId.split(",");
        this.title = "活动信息培训评分";
      });
    },
    handleClick(activityId) {
      this.Regi = true;
      this.activityId = activityId;
    },
    //评分
    score() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateScore(this.form).then(res => {
            this.$modal.msgSuccess("评分成功");
            this.open = false;
            this.show = false;
            this.getList();
          });
        }
      });
    },
    handlePictureCardPreview(id) {
      this.uploadId = id;
      this.openFileList = true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.activityId != null) {
            updateTraining(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTraining(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.show = false;
              this.getList();
            });
          }
        }
      });
    },
  },
};
</script>
<style scoped>
.hyperlink {
  color: #007bff;
  /* 蓝色 */
  text-decoration: underline;
  cursor: pointer;
}
</style>
